package com.xtjc03.serial.codec;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolDecoderAdapter;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.Charset;
import java.util.Arrays;

public class ComMsgDecoder extends ProtocolDecoderAdapter {

    private static final Logger logger = LoggerFactory.getLogger(ComMsgDecoder.class);

    @Override
    public void decode(IoSession ioSession, IoBuffer ioBuffer, ProtocolDecoderOutput protocolDecoderOutput) throws Exception {
        logger.info("[Debug]:ComMsgDecoder.decode");
        byte[] array = new byte[ioBuffer.capacity()];
        ioBuffer.get(array);
        protocolDecoderOutput.write(new String(array, Charset.forName("gbk")));
    }

}
